package merisis.util;

import org.apache.solr.util.OpenBitSet;

public class OpenBitSetImpl extends OpenBitSet implements BitSet {

	public void or(BitSet s) {

		super.or((OpenBitSet) s);
	}

	public void and(BitSet s) {

		super.and((OpenBitSet) s);
	}

	public void andNot(BitSet s) {
		
		super.andNot((OpenBitSet) s);
	}

	public long countIntersectionWith(BitSet b) {

		return OpenBitSet.intersectionCount((OpenBitSet) this, (OpenBitSet) b);
	}

	public BitSetIterator iterator() {

		return new BitSetIterator() {

			long current = nextSetBit(0);

			public boolean hasNext() {

				return current >= 0;
			}

			public long next() {
				
				long r = current;
				current = nextSetBit(current + 1);
				return r;
			}
		};
	}

	public void mergeDiff(BitSet a, BitSet b) {

		OpenBitSetImpl bs = new OpenBitSetImpl();
		bs.or(a);
		bs.andNot(b);

		this.or((BitSet) bs);
	}

	public long[] toLongArray() {

		return BitUtil.toArray(this);
	}

	public String toString() {

		StringBuilder sb = new StringBuilder();
		sb.append('{');
		BitUtil.format(sb, this, ",");
		sb.append('}');
		return sb.toString();
	}

	public BitSet spawn() {
		// TODO Auto-generated method stub
		return null;
	}
}
